<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends VController {
    public function login(){
        if(IS_AJAX)
        {
            //ajax请求登录
            if(empty($_POST['username']) || empty($_POST['passwd']) || $_POST['username'] == '' || $_POST['passwd'] == '')
            {
                $this->ajaxReturn(array('status'=>'1'));
            }
            $username = $_POST['username'];
            $passwd = $_POST['passwd'];
            $userAdmin = D('UserAdmin');
            $result = $userAdmin->vlogin($username,md5($passwd));
            if($result)
            {
                //登录成功，写session，跳转到首页
                if($_POST['rememberMe'] === '0')
                {
                    //需要记住密码，往cokkie写数据
                    cookie('qzone',array('adminUserName'=>$username,'adminPassWd'=>md5($passwd)),604800);
                }
                $_SESSION['qzone']['admin']['id'] = $result['id'];
                $_SESSION['qzone']['admin']['username'] = $result['username'];
                $this->ajaxReturn(array('status'=>'0'));
            }else{
                $this->ajaxReturn(array('status'=>'1'));
            }
        }
        $this->display();
    }
    public function logout()
    {
        $_SESSION['qzone']['admin'] = null;
        cookie('qzone',null);
        $this->success('退出成功，请重新登录！',U('User/login'));



    }


public function jz(){
    $login=I('POST.login');

    $id=I('POST.id');

    $model=M('user');
    $data['login']='0';
    $res=$model->where("id=$id")->save($data);
    $data['login']=$login;
    $res=$model->where("id=$id")->save($data);

      if($res>0){
            $this->ajaxReturn(array('status'=>'0'));
        } else {
            $this->ajaxReturn(array('status'=>'1'));
        }

  }

   public function qx(){

    $login=I('POST.login');

    $id=I('POST.id');

    $model=M('user');
    $data['login']=$login;
    $res=$model->where("id=$id")->save($data);

      if($res>0){
            $this->ajaxReturn(array('status'=>'0'));
        } else {
            $this->ajaxReturn(array('status'=>'1'));
        }


    
}


    public function yyyh(){
    $model=M('user');
    $list=$model->where("login=1")->select();
    // var_dump($list);
    $this->assign('list',$list);
    $this->display('User/yyyh');

  }



    public function chakanyonghu(){

   

   $list=M('user')->select();

       // var_dump($list);
        $this->assign('list',$list);
        $this->display('User/chakanyonghu');
    }


  public function jz(){
    $login=I('POST.login');

    $id=I('POST.id');

    $model=M('user');
    $data['login']='0';
    $res=$model->where("id=$id")->save($data);
    $data['login']=$login;
    $res=$model->where("id=$id")->save($data);

      if($res>0){
            $this->ajaxReturn(array('status'=>'0'));
        } else {
            $this->ajaxReturn(array('status'=>'1'));
        }

  }

   public function qx(){

    $login=I('POST.login');

    $id=I('POST.id');

    $model=M('user');
    $data['login']=$login;
    $res=$model->where("id=$id")->save($data);

      if($res>0){
            $this->ajaxReturn(array('status'=>'0'));
        } else {
            $this->ajaxReturn(array('status'=>'1'));
        }





   }





  public function yyyh(){
    $model=M('user');
    $list=$model->where("login=1")->select();
    // var_dump($list);
    $this->assign('list',$list);
    $this->display('User/yyyh');

  }



    public function chakanyonghu(){

   

   $list=M('user')->select();

       // var_dump($list);
        $this->assign('list',$list);
        $this->display('User/chakanyonghu');
    }
}